package com.aididi.service.Impl;

import cn.hutool.core.lang.tree.Tree;
import com.aididi.dao.SysAuthDao;
import com.aididi.entity.SysAuth;
import com.aididi.entity.SysUser;
import com.aididi.service.SysAuthService;
import com.aididi.service.SysUserService;
import com.aididi.utils.TreeNodeUtils;
import com.aididi.utils.UserContextHolder;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: zx.xu
 * @Description:
 */
@Service
public class SysAuthSerivceImpl extends ServiceImpl<SysAuthDao, SysAuth> implements SysAuthService {

    @Autowired
    private SysUserService sysUserService;


    @Override
    public List<Tree<String>> getAuthList() {
        String userName = UserContextHolder.getCurrentUserName();
        SysUser user = sysUserService.findUserByUserName(userName);
        List<SysAuth> auths = this.baseMapper.findByUserId(user.getId());
        List<Tree<String>> treeNode = TreeNodeUtils.TreeNode(auths);
        return treeNode;
    }
}
